using System;
using System.Linq;
using Repository.Abstract;
using DomainModel.Entities;
using Repository.Concrete;
using Service.Abstract;

namespace Service.Concrete
{
    public class ProjectService : BaseService<Project>, IProjectService
    {
        private readonly IProjectRepository _projectRepository;

        public ProjectService(IProjectRepository projectRepository)
            : base(projectRepository)
        {
            _projectRepository = projectRepository;
        }

        // no welcome to use
        public ProjectService()
            : base(new SqlProjectRepository(Configuration.Configuration.ConectionString))
        {
            _projectRepository =
                new SqlProjectRepository(Configuration.Configuration.ConectionString);
        }

        public override IQueryable<Project> GetAllByUserId(Guid userId)
        {
            return base.GetAllByUserId(userId).Where(x => x.UserId == userId);
        }

        public Project GetProjectById(int projectId)
        {
            return _projectRepository.GetAll.Where(p => p.Id == projectId).SingleOrDefault();
        }
    }
}